package com.yvon.maple.service.system.controller;

import com.yvon.boot.common.result.ResponseData;
import com.yvon.boot.excel.ExcelUtil;
import com.yvon.boot.log.annotation.SysLog;
import com.yvon.boot.mybatis.page.ListData;
import com.yvon.boot.mybatis.page.SearchCriteria;
import com.yvon.boot.mybatis.search.BaseQuery;
import com.yvon.boot.mybatis.search.PageQuery;
import com.yvon.maple.service.system.bo.LogBo;
import com.yvon.maple.service.system.entity.Log;
import com.yvon.maple.service.system.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.yvon.boot.common.result.ResponseData.success;

/**
 * @author : Yvon
 * @since : 2022-05-13
 */
@RestController
@RequestMapping(value = "/logs")
@Api(value = "日志管理", tags = "系统服务 - 日志管理API")
@SysLog(enable = false)
public class LogController {

    @Autowired
    private LogService logService;

    @PostMapping("/set")
    @ApiOperation(value = "新增", notes = "新增API", hidden = true)
    public ResponseData set(@RequestBody Log log) {
        return success(logService.save(log));
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询", notes = "分页查询API")
    public ResponseData<ListData<Log>> page(PageQuery pageQuery) {
        ListData<Log> listData = logService.page(pageQuery, Log.class);
        return success(listData);
    }

	@GetMapping("/export")
	@ApiOperation(value = "分页查询", notes = "分页查询API")
	public void export(BaseQuery pageQuery, HttpServletResponse response) {
		List<LogBo> list = logService.list(pageQuery, LogBo.class);
		ExcelUtil.exportExcel(list, "sheet1", LogBo.class, response);
	}
}
